
# Create your views here.
from django.http import HttpResponse,Http404
from django.shortcuts import render
import urllib2


def index(request):
    
    return HttpResponse(u"hello")


def hello1(request,num):
    try:
        num = int(num)
    except ValueError:
        raise Http404()
    
def home(request):
    request_header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36'}
    url= "http://m.weibo.cn/page/json?containerid=1005055796731205_-_WEIBO_SECOND_PROFILE_WEIBO&count=20"
#     send_headers = {
#      'Host':'www.jb51.net',
#      'User-Agent':'Mozilla/5.0 (Windows NT 6.2; rv:16.0) Gecko/20100101 Firefox/16.0',
#      'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
#      'Connection':'keep-alive'
#     }
    req = urllib2.Request(url,None,request_header)
    r = urllib2.urlopen(req)
    
    return render(request,'home.html',{'string':r.read()})